﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Maticsoft.DBUtility;
using System.Data.SqlClient;

namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 数据类PaperCls
    /// </summary>
    public class PaperCls
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public PaperCls()
        { }

        /// <summary>
        /// 是否存在该记录
        /// <creator>chenly</creator>
        /// <date>2013-7-17</date>
        /// </summary>
        /// <param name="fPaperClsNo">类别编号</param>
        /// <param name="fEntityNo">公司编号</param>
        /// <returns>是否存在</returns>
        public bool Exists(string fPaperClsNo, string fEntityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from t_PaperCls");
            strSql.Append(" where FPaperClsNo=@FPaperClsNo and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FPaperClsNo", SqlDbType.VarChar,30),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)			};
            parameters[0].Value = fPaperClsNo;
            parameters[1].Value = fEntityNo;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 增加一条数据
        /// <creator>chenly</creator>
        /// <date>2013-7-17</date>
        /// </summary>
       /// <param name="model">model对象</param>
       /// <returns>返回是否有记录，有就存</returns>
        public bool Add(Model.PaperCls model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_PaperCls(");
            strSql.Append("FPaperClsNo,FPaperClsName,FEntityNo)");
            strSql.Append(" values (");
            strSql.Append("@FPaperClsNo,@FPaperClsName,@FEntityNo)");
            SqlParameter[] parameters = {
					new SqlParameter("@FPaperClsNo", SqlDbType.VarChar,30),
					new SqlParameter("@FPaperClsName", SqlDbType.NVarChar,30),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = model.FPaperClsNo;
            parameters[1].Value = model.FPaperClsName;
            parameters[2].Value = model.FEntityNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// <creator>chenly</creator>
        /// <date>2013-7-17</date>
        /// </summary>
        /// <param name="fPaperClsNo">类别编号</param>
        /// <param name="fEntityNo">公司编号</param>
        /// <returns>返回是否有记录，有就删除</returns>
        public bool Delete(string fPaperClsNo, string fEntityNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_PaperCls ");
            strSql.Append(" where FPaperClsNo=@FPaperClsNo and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FPaperClsNo", SqlDbType.VarChar,30),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)			};
            parameters[0].Value = fPaperClsNo;
            parameters[1].Value = fEntityNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// <creator>chenly</creator>
        /// <date>2013-7-17</date>
        /// </summary>
        /// <param name="fPaperClsNo">类别编号</param>
        /// <param name="fEntityNo">公司编号</param>
        /// <returns>一个对象实体</returns>
        public Model.PaperCls GetModel(string fPaperClsNo, string fEntityNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FPaperClsNo,FPaperClsName,FEntityNo from t_PaperCls ");
            strSql.Append(" where FPaperClsNo=@FPaperClsNo and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FPaperClsNo", SqlDbType.VarChar,30),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)			};
            parameters[0].Value = fPaperClsNo;
            parameters[1].Value = fEntityNo;

            Model.PaperCls model = new Model.PaperCls();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["FPaperClsNo"] != null && ds.Tables[0].Rows[0]["FPaperClsNo"].ToString() != "")
                {
                    model.FPaperClsNo = ds.Tables[0].Rows[0]["FPaperClsNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FPaperClsName"] != null && ds.Tables[0].Rows[0]["FPaperClsName"].ToString() != "")
                {
                    model.FPaperClsName = ds.Tables[0].Rows[0]["FPaperClsName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FEntityNo"] != null && ds.Tables[0].Rows[0]["FEntityNo"].ToString() != "")
                {
                    model.FEntityNo = ds.Tables[0].Rows[0]["FEntityNo"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 数据列表
        /// </summary>
        /// <param name="fEntityNo">公司编号</param>
        /// <returns>DataSet表</returns>
        public DataSet GetListByClsNo(string fEntityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FPaperClsNo,FPaperClsName,FEntityNo ");
            strSql.Append(" FROM t_PaperCls  where FEntityNo=@FEntityNo");
            strSql.Append(" order by FPaperClsNo asc");

            SqlParameter[] parameters = {
                    new SqlParameter("@FEntityNo",SqlDbType.NVarChar,15)};

            parameters[0].Value = fEntityNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获得数据列表
        /// <creator>chenly</creator>
        /// <date>2013-7-17</date>
        /// </summary>
        /// <param name="strWhere">查询条件</param>
        /// <returns>DataSet表</returns>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FPaperClsNo,FPaperClsName,FEntityNo ");
            strSql.Append(" FROM t_PaperCls ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where FEntityNo=" + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }




        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">model对象</param>
        /// <returns>是否保存</returns>
        public bool Update(ElingOA6_Admin_DSJCJ.Model.PaperCls model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_PaperCls set ");
            strSql.Append("FPaperClsName=@FPaperClsName");
            strSql.Append(" where FPaperClsNo=@FPaperClsNo and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FPaperClsName", SqlDbType.NVarChar,30),
					new SqlParameter("@FPaperClsNo", SqlDbType.VarChar,30),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = model.FPaperClsName;
            parameters[1].Value = model.FPaperClsNo;
            parameters[2].Value = model.FEntityNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }






    }
}
